import { Popup, Col, Row, Dialog, Notify } from "vant";
import { lot_onOff_set_api } from "@/api/lot.js";
import IndexHeader from "@/views/Index/_components/indexHeader/indexHeader.vue";
import IndexBtns from "@/views/Index/_components/btns/btns.vue";
import { getLocalStorage } from "@/tools/index.js";
export default {
  name: "index",
  components: {   
    [Popup.name]: Popup,
    [Col.name]: Col,
    [Row.name]: Row,
    IndexHeader,
    IndexBtns,
  },
  data() {
    return {
      // 弹窗对象
      popupObj: {
        show: false,
        overlay: false,
      },
      //顶部背景
      indexBg: {
        backgroundImage: "url(" + require("@/assets/images/indexBg.png") + ")",
        backgroundRepeat: "no-repeat",
        backgroundSize: "cover",
      },
      // 查询入参
      queryCondition: {
        //机构id
        orgId: getLocalStorage("loginInfo").orgId,
        // 类型
        cmd: "",
        // 区域id
        areaId: "",
        // 设备类型id
        equipmentTypeId: "",
        // 设备命令
        equipmentCmd: [],
      },
    };
  },
  created() {},
  mounted() {},
  methods: {
    // 开关接口
    lot_onOff_set_api() {
      let data = {
        orgId: this.queryCondition.orgId,
        cmd: this.queryCondition.cmd,
        areaId: this.queryCondition.areaId,
        equipmentTypeId: this.queryCondition.equipmentTypeId,
        equipmentCmd: this.queryCondition.equipmentCmd,
      };
      console.info("lot_onOff_set_api开关接口入参" + JSON.stringify(data));
      lot_onOff_set_api(data)
        .then((res) => {
          console.info(
            "lot_equipmentControl_page_api设备控制分页查询出参" +
              JSON.stringify(res)
          );
          if (res.status == 200) {
            Notify({ type: "success", message: "设备操作成功" });
          } else {
            Notify({ type: "danger", message: res.msg });
          }
        })
        .catch((err) => {
          Notify({ type: "danger", message: "设备操作失败" });
        });
    },

    // 弹窗
    popupBtn(value) {
      this.popupObj.show = value;
    },
    // 一键开监听
    onEmitFn() {
      Dialog.confirm({
        message: "确定网点一键开机？",
      })
        .then(() => {
          this.queryCondition.cmd = "switchOn";
          // 开关接口
          this.lot_onOff_set_api();
        })
        .catch(() => {
          // on cancel
        });
    },
    // 一键关监听
    offEmitFn() {
      Dialog.confirm({
        message: "确定网点一键关机？",
      })
        .then(() => {
          this.queryCondition.cmd = "switchOff";
          // 开关接口
          this.lot_onOff_set_api();
        })
        .catch(() => {
          // on cancel
        });
    },
    // 关闭弹窗监听
    popupEmitFn() {
      this.popupObj.show = false;
    },
  },
};
